package com.wnx.db;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import com.wnx.entity.Goods;
import com.wnx.entity.Purchase;
import com.wnx.util.HibernateUtil;

public class PurDao {
	public String saveP(Purchase purchase){
		 String message = "error";
		 Session session = new HibernateUtil().getSession();
		 Transaction transaction = session.beginTransaction();
		 session.save(purchase);
		 transaction.commit();
		 session.close();
		 message = "success";
		 return message;
	 }
	public List getPurchaseByUid(Purchase purchase){
		Session session = new HibernateUtil().getSession();
		Transaction transaction = session.beginTransaction();
		String hql = "from Purchase where uid=?";
		Query<Purchase> query = session.createQuery(hql,Purchase.class);
		query.setParameter(0, purchase.getUid());
		List list=query.list();
        transaction.commit();
        session.close();
		return list;
	}
	public Purchase updPurchaseState(Purchase purchase){
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		String hql ="update Purchase set state=1 where id=?";
		Query query = session.createQuery(hql);
		query.setParameter(0, purchase.getId());
		query.executeUpdate();
		transaction.commit();
        session.close();
		return purchase;
		
	}
}
